package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.fivehero.FiveHeroConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.fivehero.FiveHeroMgr;

import java.util.ArrayList;
import java.util.List;

public class FiveHeroRecycleStragety extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        FiveHeroConfig config = FiveHeroMgr.getConfig();
        if(config != null){
            ActivityInfo activityInfo = config.getActivityInfo();
            if (activityInfo != null) {
                //招募文书这个直接没有转换的移除掉
                addRecycleItemData(activityInfo,config.getBookItemId(),0);
                //体力道具又不清了
//                addRecycleItemData(activityInfo,config.getEnergItemId(),0);
            }
        }
    }

    private void addRecycleItemData(ActivityInfo activityInfo, int itemId, int scoreId) {
        List<String> paramList = new ArrayList<>();
        long recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(scoreId));
        paramList.add("0");
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 1, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.RankUnionWar.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if(Integer.valueOf(data.getParamList().get(1)) != 0){
            item2Score(userId, data);
        }else{
            removeItem(userId,data);
        }
    }


    private void removeItem(long userId,ActivityItemRecycleData data){
        int itemId = data.getItemId();
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if (userBagItem == null || userBagItem.getNum() <= 0) {
            return;
        }
        removeItem(userBagItem);
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
